package org.madgecko.api.controller;

import org.madgecko.basic.model.AjaxReturn;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author       : MadFrog
 * Date         : 2018/11/30 15:04
 * Description  : 温湿度控制器
 */
@Controller
public class IotController {

    @ResponseBody
    @RequestMapping(value = "/iot/reportHumiture", produces={"application/json; charset=UTF-8"})
    public AjaxReturn reportHumiture(Integer temperature, Integer humidity){
        if(temperature==null||humidity==null){
            return new AjaxReturn(false, "温湿度不能为空");
        }
        return new AjaxReturn(true, "温湿度报告成功");
    }

    @ResponseBody
    @RequestMapping(value = "/iot/readHumiture", produces={"application/json; charset=UTF-8"})
    public AjaxReturn readHumiture(){
        int temperature = (int)(Math.random()*100+1);
        int humidity = (int)(Math.random()*100+1);
        Humiture humiture = new Humiture(temperature, humidity);
        return new AjaxReturn(true, humiture);
    }

    class Humiture{
        private int temperature;
        private int humidity;

        public Humiture() {
        }

        public Humiture(int temperature, int humidity) {
            this.temperature = temperature;
            this.humidity = humidity;
        }

        public int getTemperature() {
            return temperature;
        }

        public void setTemperature(int temperature) {
            this.temperature = temperature;
        }

        public int getHumidity() {
            return humidity;
        }

        public void setHumidity(int humidity) {
            this.humidity = humidity;
        }
    }

}
